""" 
rgb灯光控制 WS2812B 彩灯 

1.microPython 无法纳秒(ns)延时, 故无法直接控制WS2812B
2.使用neopixel库

"""

from machine import Pin
from neopixel import NeoPixel
import time


rgb_pin_num = 16
rgb_pin = Pin(rgb_pin_num, Pin.OUT)
rgb_led = NeoPixel(rgb_pin, 1)

# 定义RGB颜色
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
BLANK = (0, 0, 0)
COLORS = (RED, GREEN, BLUE, BLANK)

if __name__ == "__main__":
    while True:
        rgb_led[0] = RED
        rgb_led.write()
        time.sleep(2)

        rgb_led[0] = GREEN
        rgb_led.write()
        time.sleep(2)

        rgb_led[0] = BLUE
        rgb_led.write()
        time.sleep(2)

        rgb_led[0] = BLANK
        rgb_led.write()
        time.sleep(2)
